//
//  SSRequest.h
//  SSNetworkDemo
//
//  Created by su on 16/6/15.
//  Copyright © 2016年 SS. All rights reserved.
//

#import <Foundation/Foundation.h>

@class SSRequest;
@class SSResponse;

extern NSString *SSRequestNetworkStatusChanged;

typedef NS_ENUM(NSInteger, SSNetworkStatus) {
    SSNetworkStatusUnknown          = -1,
    SSNetworkStatusNotReachable     = 0,
    SSNetworkStatusReachableWWAN    = 1,
    SSNetworkStatusReachableWiFi    = 2
};

typedef NS_ENUM(NSInteger, SSRequestMethod) {
    GET = 0,
    POST = 1,
    PUT = 2,
    DELETE = 3,
    PATCH = 4,
    HEAD = 5
};

typedef void (^SSRequestCallback)(SSResponse *response);


@protocol SSRequestDelegate <NSObject>

- (void) startRequest:(SSRequest *)request;
- (void) request:(SSRequest *)request didFinish:(SSResponse *)response;

@end


@interface SSRequest : NSObject

#pragma mark - public static
/**
 *  全局设置网络请求调试信息的开关
 *
 *  @param on true 打开， false 关闭。默认打开
 */
+ (void) SetDebugLoggerSwitch:(BOOL)on;
/**
 *  全局设置api接口的基本路径
 *
 *  @param basePath 基本路劲
 */
+ (void) SetApiBasePath:(NSString *)basePath;

//+ (

/**
 *  全局设置请求HTTP头，对以后所有的请求都有效果
 *
 *  @param header http头
 *  @param value  http头 值
 */
+ (void) SetHTTPHeader:(NSString *)header value:(NSString *)value;

+ (void) MonitorNetWorkStatus;

+ (SSNetworkStatus) NetworkStatus;
+ (BOOL) IsReachable;
+ (BOOL) IsReachableWWAN;
+ (BOOL) IsReachableWiFi;

+ (SSRequest *) requestWithUrl:(NSString *)url;
+ (SSRequest *) requestWithUrl:(NSString *)url parameters:(NSDictionary *)parameters;

+ (SSRequest *) requestWithUrl:(NSString *)url
                    parameters:(NSDictionary *)parameters
                        method:(SSRequestMethod)method;

#pragma mark - public properties
@property(readonly, nonatomic, assign) SSNetworkStatus networkStatus;
@property(readonly, nonatomic, assign, getter=isReachable) BOOL reachable;
@property(readonly, nonatomic, assign, getter=isReachableWWAN) BOOL reachableWWAN;
@property(readonly, nonatomic, assign, getter = isReachableWiFi) BOOL reachableWiFi;
@property(nonatomic, assign) SSRequestMethod method;


#pragma mark - public methods
/**
 *  取消请求
 */
- (void) cancel;

/**
 *  发送请求
 */
- (void) send;

/**
 *  发送请求，请求完成之后回调
 *
 *  @param callback 回调代码块
 */
- (void) sendWithCallback:(SSRequestCallback)callback;

/**
 *  设置同步请求
 *
 *  @param sync 默认都是false，异步请求，设置成true的时候，同步请求
 */
- (void) setSynchronous:(BOOL)sync;

/**
 *  增加请求参数
 *
 *  @param parameters 请求参数
 */
- (void) addParameters:(NSDictionary *)parameters;

@end
